package com.zzh.lib.plugin;

import android.app.Application;

import com.zzh.lib.plugin.app.AndroidApiHook;
import com.zzh.lib.plugin.msg.PluginInitializer;

import org.xutils.http.common.util.LogUtil;
import org.xutils.http.xHttp;


/**
 * @Date: 2021/5/27 09:31
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 初始化入口
 */
public final class PluginRuntime {

    private static PluginRuntimeListener runtimeListener;

    private PluginRuntime() {
    }

    public static void init(Application app, PluginRuntimeListener listener) {
        runtimeListener = listener;
        boolean isDebug = listener.isDebug();
        xHttp.getInstance().init(app);
        PluginInitializer.init();

        try {
            AndroidApiHook.hookInstrumentation();
        } catch (Throwable ex) {
            LogUtil.e(ex.getMessage(), ex);
        }

        try {
            AndroidApiHook.hookActivityManager();
        } catch (Throwable ex) {
            LogUtil.d(ex.getMessage(), ex);
        }

        try {
            AndroidApiHook.hookPackageManager();
        } catch (Throwable ex) {
            LogUtil.d(ex.getMessage(), ex);
        }
    }


    public static PluginRuntimeListener getRuntimeListener() {
        return runtimeListener;
    }
}
